# -*- coding: utf-8 -*-

import abc

from component import Component


class SqlExecutor(Component):

    def _init(self):
        super(SqlExecutor, self)._init()

        self.__sql = None
        self.__params = []

    @property
    def sql(self):
        return self.__sql

    @sql.setter
    def sql(self, sql):
        self.__sql = sql

    @property
    def params(self):
        return self.__params

    @params.setter
    def params(self, params):
        self.__params = params

    def empty_params(self):
        self.__params[:] = []

    @abc.abstractmethod
    def close(self):
        raise NotImplementedError('call to abstract method %s.close' % (self.__class__,))

    @abc.abstractmethod
    def reset(self):
        raise NotImplementedError('call to abstract method %s.reset' % (self.__class__,))

    @abc.abstractmethod
    def begin_transaction(self):
        raise NotImplementedError('call to abstract method %s.begin_transaction' % (self.__class__,))

    @abc.abstractmethod
    def commit(self):
        raise NotImplementedError('call to abstract method %s.commit' % (self.__class__,))

    @abc.abstractmethod
    def rollback(self):
        raise NotImplementedError('call to abstract method %s.rollback' % (self.__class__,))

    @abc.abstractmethod
    def execute_non_query(self):
        raise NotImplementedError('call to abstract method %s.execute_non_query' % (self.__class__,))

    @abc.abstractmethod
    def execute_scalar(self):
        raise NotImplementedError('call to abstract method %s.execute_scalar' % (self.__class__,))

    @abc.abstractmethod
    def execute_dataset(self):
        raise NotImplementedError('call to abstract method %s.execute_dataset' % (self.__class__,))

    def _destroy(self):
        try:
            self.close()
        except:
            pass
